using System.Drawing;
using UnityEngine;
using UnityEngine.UI;
public class HealthBar : MonoBehaviour
{
    public bool alwaysVisible;
    public float visibleTime;
    public Transform barPoint;
    private UnityEngine.UI.Image healthSlider;
    private float timeLeft;
    DataController dataController;
    void Awake()
    {

        dataController = GetComponent<DataController>();
        // dataController.upDateHealthBar += UpdateHpBar;
    }

    void OnEnable()
    {
        //实例化ui血条
        // UIbar = Instantiate(healthUiPrefab, barPoint.transform).transform;
        // healthSlider = UIbar.GetChild(0).GetComponent<UnityEngine.UI.Image>();

        // UIbar.gameObject.SetActive(alwaysVisible);
    }
    private void UpdateHpBar(float currentHealth, float maxHealth)
    {
        healthSlider.fillAmount = currentHealth / maxHealth;
    }

    void LateUpdate()
    {
        // if (UIbar != null)
        // {
        //     UIbar.position = barPoint.position;
        //     if (timeLeft <= 0 && !alwaysVisible)
        //         UIbar.gameObject.SetActive(false);
        //     else
        //         timeLeft -= Time.deltaTime;

        // }
    }
    public void Die()
    {
        // Destroy(UIbar.gameObject);                       // 完成后销毁
    }
}
